package com.example.pointerdemo

import android.annotation.SuppressLint
import android.os.Build
import android.view.View
import android.view.ViewGroup
import androidx.core.view.children

/**
 * @Author xiao
 * @Date 2021/6/17
 * @Description
 */
object HookClickHelper {

    fun hook(view: View) {
        if (view is ViewGroup) {
            view.children.forEach { childView ->
                if (childView is ViewGroup) {
                    hook(childView)
                } else {
                    setHook(childView)
                }
            }
        } else {
            setHook(view)
        }
    }

    @SuppressLint("DiscouragedPrivateApi", "PrivateApi")
    private fun setHook(view: View) {
        view.accessibilityDelegate = TrackingAccessibilityDelegate()
    }
}